package cn.ybk.system.controller;


import cn.ybk.basic.util.AjaxResult;
import cn.ybk.basic.util.PageList;
import cn.ybk.system.domain.SystemDetail;
import cn.ybk.system.domain.SystemType;
import cn.ybk.system.query.SystemDetailQuery;
import cn.ybk.system.service.SystemDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/detail")
public class SystemDetailController {

    @Autowired
    private SystemDetailService systemDetailService;

    @GetMapping
    public List<SystemDetail> findAll() {
        return systemDetailService.findAll();
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDetail systemDetail) {
        Long id = systemDetail.getId();
        if (id == null) {
            systemDetailService.add(systemDetail);
        } else {
            systemDetailService.update(systemDetail);
        }
        return new AjaxResult().me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        systemDetailService.delete(id);
        return new AjaxResult().me().success();
    }

    // 分页 + 查询
    @PostMapping
    public PageList<SystemDetail> queryByPage(@RequestBody SystemDetailQuery query) {
        return systemDetailService.queryByPage(query);
    }

    @PatchMapping
    public AjaxResult batch(@RequestBody List<Long> ids) {
        systemDetailService.batch(ids);
        return AjaxResult.me().success();
    }

    @GetMapping("/drawer/{id}")
    public  List<SystemDetail> drawer(@PathVariable("id") Long id){
        return systemDetailService.drawer(id);
    }

}
